// JavaScript Document

head.js("js/maps/map_001.js");

/**
 * Initializes variables in main.js file
 */
function loadingReady() {
	var map = mapFiles[mapFiles.length - 1];
	if (map) {
		level.name = map.name;
		level.spawnPos = map.spawnPos;

        for (var i = 0; i < players.length; i++){

            players[i].setPos(level.spawnPos.x[i], level.spawnPos.y[i]);
        }

		level.map = rows2cols(map.map);
	}
	mapLoaded = true;
}

/**
 * This is a transpose function. Changes lines to columns and contrary
 * 
 * @param map array [[a1, a2, ...], [a1, a2, ...], ...]
 * @return array [[a1, b1, ...], [a2, b2, ...], ...]
 */
function rows2cols(map) {
	var r = [];
	var t;
	for (var i = 0, iLen = map.length; i < iLen; i ++) {
		t = map[i];
		for (var j = 0, jLen = t.length; j < jLen; j ++) {
			if (!r[j]) {
				r[j] = [];
			}
			r[j][i] = t[j];
		}
	}
	return r;
}